package com.xsy.android.compose.wandroid

import com.xsy.android.compose.wandroid.logic.utils.DataStoreUtils

/**
 *@author: xiaosy
 *时间: 2024/7/17
 *@Description: java类作用描述
 *@Version: 1.0
 **/
object Play {
    private const val USER_NAME = "username"
    private const val NICK_NAME = "nickname"
    private const val IS_LOGIN = "isLogin"
    private var dataStore = DataStoreUtils

    fun initialize(dataSourceUtils: DataStoreUtils) {
        dataStore = dataSourceUtils
    }


    var isLogin: Boolean
        get() = dataStore.readBooleanData(IS_LOGIN)
        set(value) {
            dataStore.saveSyncBooleanData(IS_LOGIN, value)
        }

    fun logout() {
        dataStore.clearSync()
    }

    fun setUserInfo(nickname: String, username: String) {
        dataStore.saveSyncStringData(NICK_NAME, nickname)
        dataStore.saveSyncStringData(USER_NAME, username)
    }

    val nickname: String
        get() = dataStore.readStringData(NICK_NAME)
    val username: String
        get() = dataStore.readStringData(USER_NAME)
}